#pragma once
#include "DXAMLCommon.h"

#include "CDOCollection.h"

class CStyle;
class CResourceDictionaryCollection;


class CDependencyObject;

class CResourceDictionary :
	public CDOCollection
{
protected: 
	CResourceDictionary(CCoreServices * pCore);
public: 
	virtual ~CResourceDictionary();
	static HRESULT Create(CDependencyObject * * ppObject, CREATEPARAMETERS * pCreate);
	virtual XUINT32 GetTypeIndex() const;
	virtual HRESULT InitInstance();
	virtual HRESULT SetValue(CDependencyProperty * pdp, CValue * pValue);
	virtual HRESULT Add(XUINT32 cKey, XUINT16 * pKey, CValue * pValue, CValue * pResult, XBOOL fKeyIsType);
	virtual HRESULT Remove(XUINT32 cKey, XUINT16 * pKey, XBOOL fKeyIsType);
	virtual HRESULT GetKey(XUINT32 cKey, XUINT16 * pKey, CDependencyObject * * ppDO, XBOOL bLocalOnly, XBOOL fKeyIsType, XBOOL bShouldCheckThemeResources, XBOOL * pbResourceFromReadOnlyDictionary);
	virtual HRESULT GetKeyAtIndex(XINT32 index, CValue * pKey, XBOOL * pbIsImplicitStyle);
	XBOOL HasImplicitStyle();
	XBOOL HasImplicitDataTemplate();
	XUINT32 GetImplicitStylesCount();
	virtual XBOOL ParticipatesInManagedTreeInternal();
	virtual XBOOL ShouldEnsureNameResolution();
	virtual HRESULT Append(CDependencyObject * pObject, XUINT32 * pnIndex);
	virtual HRESULT Clear();
	virtual void * RemoveAt(XUINT32 nIndex);
	virtual HRESULT OnAddToCollection(CDependencyObject * pDO);
	virtual HRESULT OnRemoveFromCollection(CDependencyObject * pDO, XINT32 iPreviousIndex);
	HRESULT SetResourceOwner(CDependencyObject * pResourceOwner);
	void SetIsThemeDictionaries(XBOOL bIsThemeDictionaries);
protected: 
	virtual HRESULT ChildEnter(CDependencyObject * pChild, CDependencyObject * pNamescopeOwner, struct EnterParams params, XBOOL fCanProcessEnterLeave);
	virtual HRESULT ChildLeave(CDependencyObject * pChild, CDependencyObject * pNamescopeOwner, struct LeaveParams params, XBOOL fCanProcessEnterLeave);
	virtual HRESULT AddKey(XUINT32 cKey, XUINT16 * pKey, CValue * pValue, XBOOL fKeyIsType);
private: 
	HRESULT RemoveKey(struct KeyValuePair * pKVP);
	virtual HRESULT RemoveKey(XUINT32 cKey, XUINT16 * pKey, XBOOL fKeyIsType);
	HRESULT LoadFromSource();
	struct IValueStore * m_pStore;
	struct IValueStore * m_pImplicitResourceStore;
	XUINT32 m_nImplicitStylesCount;
	XUINT32 m_nImplicitDataTemplateCount;
	CXcpList<KeyValuePair> * m_pList;
	bool m_bHasKey;
	bool m_bAllowItems;
	XBOOL m_bIsThemeDictionaries;
	CDependencyObject * m_pResourceOwner;
	CResourceDictionary * m_pThemeDictionary;
private: 
	HRESULT NotifyImplicitStyleChanged(CStyle * pOldStyle, CStyle * pNewStyle);
	HRESULT CycleCheckInternal(CResourceDictionary * pOriginalItem);
	HRESULT InvalidateImplicitStyles(CResourceDictionary * pOldResources);
public: 
	CXString * m_pstrSource;
	CResourceDictionaryCollection * m_pMergedDictionaries;
	CResourceDictionary * m_pThemeDictionaries;


};